<template>
  <div class="topbox">
    <img :src="supplier.shopLogo" alt="">
    <div>
      <div class="topinfo">
        <a-popover placement="bottom">
          <template slot="content">
            <div class="supplier-title">{{supplier.shopName}}</div>
            <div class="supplier-rate">
              <div class="supplier-rate-item" v-for="(item,index) in supplier.rateList" :key="index">
                <svg-icon size="12" :icon-class="item.icon"></svg-icon>
                <span>{{ item.name }}</span>
                <div class="rate-item-star-wrapper">
                  <rate-star :rate="item.rate" size="small"></rate-star>
                </div>
              </div>
            </div>
            <a-tabs size="small" style="width: 288px;" :tabBarGutter="0">
              <a-tab-pane v-for="(i,k) in supplier.shopContact.filter(v=>v.isShow)" :key="k" :tab="'联系人'+(k+1)">
                <div>联系人：{{ i.contactName || '-' }}</div>
                <div>电话：{{ i.contactPhone || '-' }}</div>
                <div>邮件：{{ i.contactEmail || '-' }}</div>
                <div>办公：{{ i.contactTel || '-' }}</div>
                <div>备注：{{ i.remark || '-' }}</div>
              </a-tab-pane>
            </a-tabs>
          </template>
          <span class="topname">{{supplier.shopName}}</span>
        </a-popover>
        <svg-icon @click="toServer" size="20" icon-class="consult" style="cursor: pointer;"></svg-icon>
        <span @click="toServer" class="topconc">联系客服</span>
      </div>
      <rate-star :rate="0"></rate-star>
    </div>
  </div>
</template>

<script>
import RateStar from '@/components/RateStar'
import {onlineService} from '@/api/portal'
import storage from '@/utils/storage'

export default {
  name: 'infoPopover',
  components: { RateStar },
  props: {
    supid: {
      type: String,
      default: ''
    },
    supplier: {
      type: Object,
      default: ()=>({
        name: '',
        shopContact: [],
        rateList: [
          {name: '服务', rate: 0, icon: 'service'},
          {name: '质量', rate: 0, icon: 'quality'},
          {name: '价格', rate: 0, icon: 'price'},
          {name: '体验', rate: 0, icon: 'delivery'}
        ]
      })
    }
  },
  data() {
    return {
      chatUrl:''
    }
  },
  created(){
    this.onService()
  },
  methods:{
    toServer(){
      if(this.chatUrl)window.open(this.chatUrl)
    },
    async onService(){
      let info = storage.session.get('userInfo')
      let openid = info.phone || ''
      let res = await onlineService({supplierId: this.supid})
      this.chatUrl = res.data
    },
  }
}
</script>

<style scoped lang="scss">
$width: 1200px;
$mainColor: #0078FE;
.topbox{
  margin: 20px auto;
  width: $width;
  background-color: #e5f1ff;
  height: 88px;
  display: flex;
  align-items: center;
  border-radius: 10px;
  img{
    // width: 240px;
    height: calc(100% - 20px);
    background-color: #eee;
    margin: 10px 30px 10px 10px;
  }
  .topinfo{
    cursor: pointer;
    display: flex;
    align-items: center;
  }
  .topname{
    max-width: 777px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    font-size: 20px;
    font-weight: 600;
    margin-right: 10px;
  }
  .topconc{
    color: $mainColor;
    margin-left: 10px;
  }
}
.supplier-title{
  width: 288px;
  font-size: 16px;
  padding-bottom: 10px;
  border-bottom: 1px dotted #ccc;
}
.supplier-rate {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  width: 288px;
  .supplier-rate-item {
    display: flex;
    align-items: center;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC, sans-serif;
    color: #646464;
    margin-top: 10px;

    &:nth-child(2n) {
      margin-left: 10px;
    }

    span {
      margin-left: 6px;
      margin-right: 8px;
    }
  }
}
</style>
